package cn.cocho.android.mct.file;

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import cn.cocho.android.mc.file.FileUtils;

/**
 * 文件工具包相关函数的测试用例
 * 
 * @author yzl
 * @time 2013-5-3上午11:42:13
 */
public class FileUtilsTest {
	
	private static String currentPath=null;
	private static String filePath=null;

	@Before
	public void setUp() throws Exception {
		getCurrentPath();
	}
	
	/**
	 * 获取当前路径
	 *
	 * @author yzl
	 * @time 2013-5-3上午11:56:02
	 */
	public static String getCurrentPath() {
		if (currentPath == null) {
			currentPath = System.getProperty("user.dir");
			filePath=currentPath+"\\test\\"+"create.txt";
		}
		return currentPath;
	}

	@Test
//	@Ignore
	public void testCreateFile() {
		String filePath=currentPath+"\\create.txt";
		boolean isCreate=FileUtils.createFile(filePath);
		assertEquals("创建文件失败！", true, isCreate);
	}

	@Test
//	@Ignore
	public void testWriteFile() {
		String content="测试数据1234567890qwertyuio!@#$%^&*()~`?><}{|:;'.,/测试数据1234567890qwertyuio!@#$%^&*()~`?><}{|:;'.,/";
		boolean isWrite=FileUtils.writeFile(filePath, content);
		assertEquals("写文件失败！", true, isWrite);
	}

	@Test
//	@Ignore
	public void testAppendFile() {
		String content="追加信息-----------------------------";
		boolean isWrite=FileUtils.appendFile(filePath, content);
		assertEquals("写文件失败！", true, isWrite);
	}

	/**
	 * 需指定文件：例，create.txt
	 *
	 * @author yzl
	 * @time 2013-5-3上午11:57:28
	 */
	@Test
//	@Ignore
	public void testRemoveFile() {
		String targetFilePath=currentPath+"\\create.txt";
//		String targetFilePath=currentPath;
		boolean isRemove=FileUtils.removeFile(filePath,targetFilePath);
		assertEquals("移动文件失败！", true, isRemove);
	}

	@Test
//	@Ignore
	public void testRnameFile() {
		String name="rename.txt";
		boolean isRname=FileUtils.rnameFile(filePath,name);
		assertEquals("文件重命名失败！", true, isRname);
	}

	@Test
//	@Ignore
	public void testDelete() {
		String delete="D:\\deleteFile";
		FileUtils.delete(delete);
	}
	
	/**
	 * 注：需要创建源文件（例，D:\\deleteFile\\1.txt）,且targetFilePath必须是文件（文件名可任意定）
	 *
	 * @author yzl
	 * @time 2013-5-3上午11:44:25
	 */
	@Test
//	@Ignore
	public void testCopyFile() {
		String sourceFilePath="D:\\deleteFile\\1.txt",targetFilePath="D:\\娱乐\\2.txt";
		boolean isCopy=FileUtils.copyFile(sourceFilePath, targetFilePath);
		assertEquals("单个文件复制失败！", true, isCopy);
	}

	/**
	 * 需指定源文件路径，及目标路径。注：如果想要将整个文件夹整体复制，则需要在目标路径中添加源文件名。
	 *
	 * @author yzl
	 * @time 2013-5-3上午11:58:14
	 */
	@Test
//	@Ignore
	public void testCopyDir() {
		String sourceDirPath="D:\\deleteFile",targetDirPath="D:\\娱乐\\deleteFile";
		FileUtils.copyDir(sourceDirPath, targetDirPath);
	}
}
